<!doctype html>
<html>

<head>
	<meta charset="UTF-8">
	<title>修改教育经历</title>
	<meta name="viewport"
		content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
	<link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">
	<link rel="stylesheet" href="css/mui.min.css" />
	<!-- build:css css/app.css -->
	<link rel="stylesheet" href="css/base.css" />
	<link rel="stylesheet" href="css/common.css" />
	<!-- endbuild -->
</head>

<body>
	<header class="mui-bar mui-bar-nav">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		<h1 class="mui-title">修改教育经历</h1>
	</header>
	<div class="mui-content">
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label><span class="red">*</span>入学时间</label>
				<input id="entry-time" type="text" placeholder="请选择" data-toggle='date' />
				<i class="mui-icon mui-icon-arrowright"></i>
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label><span class="red">*</span>毕业时间</label>
				<input id="overy-time" type="text" placeholder="请选择" data-toggle='date' />
				<i class="mui-icon mui-icon-arrowright"></i>
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label>
					<span class="red">*</span>学校
				</label>
				<input id="school" type="text" placeholder="请填写" />
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label><span class="red">*</span>学历</label>
				<input id="education" type="text" placeholder="请选择" />
				<i class="mui-icon mui-icon-arrowright"></i>
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label><span class="red">*</span>专业</label>
				<input id="major" type="text" placeholder="请填写" />
			</div>
		</div>
		<button id="save" class="button button-blue">保存</button>
	</div>
	<script src="js/mui.min.js"></script>
	<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
	<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>
	<!-- build:js js/app.js -->
	<script src="js/api.js"></script>
	<script src="js/tools.js"></script>
	<!-- endbuild -->
	<script>
		var href = window.location.href;
		var eid = 0;
		var data = {
			eid: null,
			entranceTime: null,
			graduationTime: null,
			school: '',
			degree: null,
			specialty: ''
		}
		if (href.indexOf('?') != -1) {
			eid = href.split('?')[1].split('=')[1];
		}
		function init(res) {
			if (res['entranceTime']) {
				data.entranceTime = res['entranceTime'];
				$('#entry-time').val(res['entranceTime'])
			}
			if (res['graduationTime']) {
				data.graduationTime = res['graduationTime'];
				$('#overy-time').val(res['graduationTime'])
			}
			if (res['school']) {
				data.school = res['school'];
				$('#school').val(res['school'])
			}
			if (res['degree']) {
				data.degree = config.resume_edu[res['degree']];
				$('#education').val(config.resume_edu[res['degree']])
			}
			if (res['specialty']) {
				data.specialty = res['specialty'];
				$('#major').val(res['specialty'])
			}
		}
		// 回显
		$.ajax({
			url: config.ME_API + 'h5/h5GetEducation',
			type: 'post',
			data: {
				eid: eid
			},
			success: function (res) {
				if (res.code == 2) {
					init(res.data.education)
				} else {
					mui.toast(res.msg)
				}
			}
		})
		// 入职时间
		$("#entry-time").calendar({
			onChange: function (p, values, displayValues) {
				data.entranceTime = values[0].replace(/\//g, '-')
			}
		});
		// 离职时间
		$("#overy-time").calendar({
			onChange: function (p, values, displayValues) {
				data.graduationTime = values[0].replace(/\//g, '-')
			}
		});
		// 学历
		$('#education').picker({
			title: '学历',
			cols: [
				{
					textAlign: 'center',
					values: config.resume_edu
				}
			],
			onChange: function (e) {
				data.degree = e.cols[0]['activeIndex']
			}
		})
		$('#save').on('tap', function () {
			data.eid = eid;
			data.school = $('#school').val();
			data.specialty = $('#major').val();
			console.log(data)
			if (data['entranceTime'] == null) {
				mui.toast('请选择入学时间!')
				return false
			}
			if (data['graduationTime'] == null) {
				mui.toast('请选择毕业时间!')
				return false
			}
			if (data['school'] == '') {
				mui.toast('请填写学校!')
				return false
			}
			if (data['degree'] == null) {
				mui.toast('请选择学历!')
				return false
			}
			if (data['specialty'] == '') {
				mui.toast('请填写专业!')
				return false
			}
			if (!isLogin()) {
				mui.toast('请先登录!');
				return false
			}
			$.ajax({
				url: config.ME_API + 'h5/h5EditEducation',
				type: 'post',
				data: data,
				success: function (res) {
					if (res.code == 2) {
						mui.toast('修改成功!');
						setTimeout(function () {
							window.history.back()
						}, 1000)
					} else {
						mui.toast(res.msg)
					}
				}
			})
		})
	</script>
</body>

</html>